<section class="content-header">
    <h1>Danh sách đơn hàng</h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo DOMAINAD ?>" ><i class="fa fa-dashboard"></i> Trang chủ</a></li>
        <li class="active">Đơn hàng</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <!-- header -->
            <div class="box-header">
                <div class="box-tools">
                    <div class="input-group">
                        <div class="input-group-btn">
                            <!--<a href="<?php echo DOMAINAD; ?>order/add" class="btn btn-sm btn-success" ><i class="fa fa-fw fa-plus-circle"></i> Thêm mới </a>-->
                            <a href="#messages" rel="modal" class="btn btn-sm btn-success" ><i class="fa fa-fw fa-question"></i> Trợ giúp </a>
                            <a href="<?php echo DOMAINAD; ?>home" class="btn btn-sm btn-success" ><i class="fa fa-fw fa-times-circle"></i> Đóng </a>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /header -->

            <div class="content-box-header">
                <div class="clear"></div>
            </div>

            <div class="box">
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover table-bordered">
                        <thead>
                            <tr>
                                <th width="2%"><input type="checkbox" name="all" id="checkall" /></th>
                                <th width="7%" style="text-align: center;"><?php echo $this->Paginator->sort('Order.id', 'Mã đơn hàng'); ?></th>
                                <th width="22%" style="text-align: left;">Tên khách hàng</th>
                                <th width="10%" style="text-align: left;">Địa chỉ</th>
                                <th width="10%"><?php echo $this->Paginator->sort('Order.phone', 'Số điện thoại'); ?></th>
                                <th width="10%"><?php echo $this->Paginator->sort('Order.total_amount', 'Tổng tiền'); ?></th>
                                <th width="10%"><?php echo $this->Paginator->sort('Order.created', 'Ngày tạo'); ?></th>
                                <th width="10%"><?php echo $this->Paginator->sort('Order.modified', 'Cập nhật'); ?></th>
                                <th width="12%">Hành động</th>
                            </tr>
                        </thead>
                        <tbody>

                            <?php echo $this->Form->create(null, array('url' => DOMAINAD . 'order/action_all', 'type' => 'post', 'name' => 'frm_list')); ?>
                            <?php if (!empty($Order)) : ?>
                                    <?php foreach ($Order as $key => $value) {  ?>
                                    <tr>
                                        <td width="2%"><input type="checkbox" name="chose_active[<?php echo $value['Order']['id']; ?>]" /></td>
                                        <td width="7%" style="text-align: center;">
                                            <a href="<?php echo DOMAINAD ?>order/detail/<?php echo $value['Order']['id']; ?>" title="Edit">
                                            <?php echo $value['Order']['id'] ?> <?php if(date('Y-m-d', strtotime($value['Order']['modified'])) == date('Y-m-d')) { ?><img src="<?php echo DOMAINAD ?>images/icons/iconnew.gif" alt="New" /><?php } ?></a>
                                        </td>
                                        <td width="22%" style="text-align: left;">
                                            <?php echo $value['Order']['username']; ?>
                                        </td>
                                        <td width="10%" style="text-align: left;">
                                            <?php echo $value['Order']['address']; ?>
                                        </td>
                                        <td width="10%"><?php echo $value['Order']['phone']; ?></td>
										<td width="10%"><?php echo $value['Order']['total_amount']; ?></td>
                                        <td width="10%"><?php echo date('d-m-Y', strtotime($value['Order']['created'])); ?></td>
                                        <td width="10%"><?php echo date('d-m-Y', strtotime($value['Order']['modified'])); ?></td>
                                        <td width="12%">
                                            <a href="<?php echo DOMAINAD ?>order/detail/<?php echo $value['Order']['id']; ?>" title="Edit"><img src="<?php echo DOMAINAD ?>images/icons/pencil.png" alt="Edit" /></a>
                                            <?php /*
                                            <a href="javascript:confirmDelete('<?php echo DOMAINAD ?>order/delete/<?php echo $value['Order']['id']; ?>')" title="Delete"><img src="<?php echo DOMAINAD ?>images/icons/cross.png" alt="Delete" /></a>
                                            */?>
                                            <?php
                                            if ($value['Order']['status'] == 0) {
                                                ?>
                                                <a href="<?php echo DOMAINAD ?>order/active/<?php echo $value['Order']['id']; ?>" title="Kích hoạt" class="icon-5 info-tooltip"><img src="<?php echo DOMAINAD ?>images/icons/Play-icon.png" alt="Kích hoạt" /></a>
                                            <?php
                                            } else {
                                                ?>
                                                <a href="<?php echo DOMAINAD ?>order/close/<?php echo $value['Order']['id']; ?>" title="Đóng" class="icon-4 info-tooltip"><img src="<?php echo DOMAINAD ?>images/icons/success-icon.png" alt="Ngắt kích hoạt" /></a>
                                            <?php
                                            }
                                            ?></td>
                                    </tr>
                                <?php } ?>
                            <?php else: ?>
                            <tr>
                                <td colspan="10" style="text-align: center">Không có dữ liệu</td>
                            </tr>
                            <?php endif; ?>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td colspan="10">
                                        <div class="bulk-actions align-left">
                                            <div id="box_action_all" style="float: left; margin-left: 10px;">
                                                <select name="process" id="chose_action_all" class="btn btn-sm btn-default">
                                                    <option value="none">Lựa chọn</option>
                                                    <option value="active_all">Active</option>
                                                    <option value="close_all">Hủy Active</option>
                                                    <option value="delete_all">Delete</option>
                                                </select>
                                                <input type="submit" name="submit_action_all" class="btn btn-sm btn-danger" value="Thực hiện" />
                                            </div><!--end #box_action_all-->
                                        </div><!--end #bulk-aciton-->
                                        <div class="pagination" style="float: right; margin-top: 0px;">
                                            <?php
                                            if($this->Paginator->counter('{:pages}')>1){
                                                echo $this->Paginator->first('« Đầu ', array('tag' => 'li'), null, array('class' => 'disabled', 'tag' => 'li'));
                                                echo $this->Paginator->prev('« Trước ', array('tag' => 'li'), null, array('class' => 'disabled', 'tag' => 'li'));
                                                echo $this->Paginator->numbers(array('separator' => '', 'currentTag' => 'a', 'currentClass' => 'active', 'tag' => 'li', 'first' => 1));
                                                echo $this->Paginator->next(' Tiếp »', array('tag' => 'li'), null, array('class' => 'disabled', 'tag' => 'li'));
                                                echo $this->Paginator->last('« Cuối ', array('tag' => 'li'), null, array('class' => 'disabled', 'tag' => 'li'));
                                            }
                                            ?>
                                            <script type="text/javascript">
                                                $(function() {
                                                    $(".pagination li").each(function (k, v) {
                                                        if($(this).find("a").length == 0) {
                                                            $(this).html("<a>" + $(this).html() + "</a>");
                                                        }
                                                    });
                                                });
                                            </script>
                                        </div>
                                        <div class="clear"></div>
                                    </td>
                                </tr>
                            </tfoot>
                        <?php echo $this->Form->end(); ?>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    $(function () {
        $('#btn_reset').click(function() {
            $('input[name="filter_ordercode"]').val('');
            $('input[name="filter_username"]').val('');
            $('select[name="filter_status"]').val('');
            $('input[name="filter_total_amount"]').val('');
            $('input[name="filter_created"]').val('');
            $('input[name="filter_modified"]').val('');
            $('#OrderSearchForm').submit();
        });
        $(".date").datepicker({
            format: 'dd-mm-yyyy'
        }).on('changeDate', function(ev) {
            $(this).data('datepicker').hide();
        });
    });
</script>